const fs = require('fs')
const pagesList = require('./pagesList.js')
const webDevh5 = require('./webDev.js')

const pages = {
  pages: [],
  globalStyle: {
    navigationStyle: 'custom',
    navigationBarTextStyle: 'black',
    navigationBarTitleText: '微信营销工具',
    navigationBarBackgroundColor: '#F8F8F8',
    backgroundColor: '#F8F8F8',
  },
  easycom: {
    '^u-(.*)': 'uview-ui/components/u-$1/u-$1.vue',
  },
}

pages.pages = pagesList.map((v1) => {
  return Object.assign(
    {
      path: '',
      style: {},
    },
    v1
  )
})

const manifest = {
  name: '',
  appid: '',
  description: '',
  versionName: '1.0.0',
  versionCode: '100',
  transformPx: false,
  'app-plus': {
    /* 5+App特有相关 */
    usingComponents: true,
    splashscreen: {
      alwaysShowBeforeRender: true,
      waiting: true,
      autoclose: true,
      delay: 0,
    },
    modules: {
      /* 模块配置 */
    },
    distribute: {
      /* 应用发布信息 */
      android: {
        /* android打包配置 */
        permissions: [
          '<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/>',
          '<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>',
          '<uses-permission android:name="android.permission.READ_CONTACTS"/>',
          '<uses-permission android:name="android.permission.VIBRATE"/>',
          '<uses-permission android:name="android.permission.READ_LOGS"/>',
          '<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>',
          '<uses-feature android:name="android.hardware.camera.autofocus"/>',
          '<uses-permission android:name="android.permission.WRITE_CONTACTS"/>',
          '<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>',
          '<uses-permission android:name="android.permission.CAMERA"/>',
          '<uses-permission android:name="android.permission.RECORD_AUDIO"/>',
          '<uses-permission android:name="android.permission.GET_ACCOUNTS"/>',
          '<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>',
          '<uses-permission android:name="android.permission.READ_PHONE_STATE"/>',
          '<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>',
          '<uses-permission android:name="android.permission.WAKE_LOCK"/>',
          '<uses-permission android:name="android.permission.CALL_PHONE"/>',
          '<uses-permission android:name="android.permission.FLASHLIGHT"/>',
          '<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>',
          '<uses-feature android:name="android.hardware.camera"/>',
          '<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>',
          '<uses-permission android:name="android.permission.WRITE_SETTINGS"/>',
        ],
      },
      ios: {
        /* ios打包配置 */
      },
      sdkConfigs: {
        /* SDK配置 */
      },
    },
  },
  quickapp: {
    /* 快应用特有相关 */
  },
  h5: webDevh5,
  'mp-weixin': {
    /* 微信小程序特有相关 */
    appid: '',
    setting: {
      urlCheck: false,
    },
    usingComponents: true,
  },
  'mp-alipay': {
    usingComponents: true,
  },
  'mp-baidu': {
    usingComponents: true,
  },
  'mp-toutiao': {
    usingComponents: true,
  },
  'mp-qq': {
    usingComponents: true,
  },
}

fs.writeFile('./src/pages.json', JSON.stringify(pages, null, 2), function(err) {
  if (err) {
    return console.error(err)
  }
  console.log('路由创建成功！')
})

fs.writeFile('./src/manifest.json', JSON.stringify(manifest, null, 2), function(err) {
  if (err) {
    return console.error(err)
  }
  console.log('配置创建成功！')
})
